//
//  GuideViewController.m
//  A_ProjectNetease
//
//  Created by dllo on 16/1/29.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "GuideViewController.h"
#import "AppDelegate.h"
#import "NewsViewController.h"
#import "VideoViewController.h"
@interface GuideViewController ()<UIScrollViewDelegate>
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)UIScrollView *smallScrollView;
@property(nonatomic, assign)BOOL isout;
@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 大轮播
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
    _scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.bounds)*4, CGRectGetHeight(self.view.bounds));
    _scrollView.delegate = self;
    _scrollView.pagingEnabled = YES;
    _scrollView.bounces = NO;
    for (int i=0; i<4; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)*i, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i+1]];
        [_scrollView addSubview:imageView];
    }
    // 放图片的图片框
    UIImageView *smallImageView = [[UIImageView alloc] initWithFrame:CGRectMake(80, CGRectGetHeight(self.view.bounds)/4, CGRectGetWidth(self.view.bounds)/2, CGRectGetHeight(self.view.bounds)/2)];
    smallImageView.userInteractionEnabled = YES;
    smallImageView.backgroundColor = [UIColor redColor];
//    [self.view addSubview:smallImageView];
    
    // 小轮播
    self.smallScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(smallImageView.bounds), CGRectGetHeight(smallImageView.bounds))];
    _smallScrollView.scrollEnabled = NO;
    _smallScrollView.delegate = self;
    _smallScrollView.contentSize = CGSizeMake(CGRectGetWidth(smallImageView.bounds)*4, CGRectGetHeight(smallImageView.bounds));
    _smallScrollView.pagingEnabled = YES;
    _smallScrollView.bounces = NO;
    for (int i=0; i<4; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(smallImageView.bounds)*i, 0, CGRectGetWidth(smallImageView.bounds), CGRectGetHeight(smallImageView.bounds))];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i+1]];
        [_smallScrollView addSubview:imageView];
    }
//    [smallImageView addSubview:_smallScrollView];
    [self.view addSubview:_scrollView];
//    [self.view bringSubviewToFront:smallImageView];
    
    // 内存管理
    ;
    
}
// 大轮播滚动时 小轮播跟随滚动
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView{
    if (aScrollView.contentOffset.x >3*self.view.frame.size.width - 1) {
                _isout = YES;
            }

    if (aScrollView == _scrollView) {
        CGPoint point = _scrollView.contentOffset;
        point.y = point.y*4;
        _smallScrollView.contentOffset = CGPointMake(_scrollView.contentOffset.x/2, _scrollView.contentOffset.y);
    }
}

// 已经结束滚动时 改变根试图
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    AppDelegate *app = [[UIApplication sharedApplication] delegate];
    if (_isout) {
        [UIView animateWithDuration:0.5 animations:^{
            _scrollView.alpha = 0;
            
        } completion:^(BOOL finished) {
            
            [_scrollView removeFromSuperview];
            app.window.rootViewController = app.tabBar;
            
        }];
        
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
